//
//  MessageViewController.m
//  BanBanApp
//
//  Created by 副团长 on 16/6/22.
//  Copyright © 2016年 时伟平. All rights reserved.
//

#import "MessageViewController.h"
//#import "GSegment.h"
#import "MessageMainViewController.h"
#import "BBSViewController.h"

@interface MessageViewController ()

@property (nonatomic, strong)MessageMainViewController *messageMainVC;
@property (nonatomic, strong)BBSViewController *bbsVC;

@end

@implementation MessageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = UIColorFromRGB(0xFAFBFD);
    
    NSArray *items = @[@"办",@"伴"];
    UISegmentedControl *segmentC = [[UISegmentedControl alloc]initWithItems:items];
    [segmentC addTarget:self action:@selector(Change:) forControlEvents:(UIControlEventValueChanged)];
    segmentC.selectedSegmentIndex = 0;
//    segmentC.segmentedControlStyle = UISegmentedControlStyleBar;
    self.navigationItem.titleView = segmentC;
    
    self.messageMainVC = [[MessageMainViewController alloc]init];
    self.messageMainVC.navigationController = self.navigationController;
    _messageMainVC.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-STATUS_AND_NAVIGATION_HEIGHT);
    [self addChildViewController:_messageMainVC];
    [self.view addSubview:_messageMainVC.view];
    
    
    self.bbsVC = [[BBSViewController alloc]init];
    self.bbsVC.navigationController = self.navigationController;
    _bbsVC.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-STATUS_AND_NAVIGATION_HEIGHT);
    [self addChildViewController:_bbsVC];
    
    

}


-(void)Change:(UISegmentedControl *)s{
    switch (s.selectedSegmentIndex) {
        case 0:
            
            [_bbsVC.view removeFromSuperview];
            [self.view addSubview:_messageMainVC.view];
            
            break;
            
          
        case 1:
            
            [_messageMainVC.view removeFromSuperview];
            [self.view addSubview:_bbsVC.view];
            
            break;
            
        default:
            break;
    }


}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
